package com.matthewmadson.util.regex;

enum TokenType
{
	DELIM,
	TOKEN
}

public class Token
{
	private String text;
	private TokenType type;
	
	Token(final String text, final TokenType type)
	{
		this.setText(text);
		this.setType(type);
	}

	private void setText(final String text)
	{
		this.text = text;
	}

	public String getText()
	{
		return text;
	}

	private void setType(TokenType type)
	{
		this.type = type;
	}

	public TokenType getType()
	{
		return type;
	}
	
	public boolean isToken()
	{
		return this.getType() == TokenType.TOKEN;
	}
	
	public boolean isDelimiter()
	{
		return this.getType() == TokenType.DELIM;
	}

	@Override
	public int hashCode()
	{
		final int prime = 31;
		int result = 1;
		result = prime * result + ((text == null) ? 0 : text.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj)
	{
		if(this == obj)
			return true;
		if(obj == null)
			return false;
		if(!(obj instanceof Token))
			return false;
		Token other = (Token) obj;
		if(text == null)
		{
			if(other.text != null)
				return false;
		}
		else if(!text.equals(other.text))
			return false;
		if(type == null)
		{
			if(other.type != null)
				return false;
		}
		else if(!type.equals(other.type))
			return false;
		return true;
	}
	
	@Override
	public String toString()
	{
		return this.text + "=" + this.type.toString();
	}
}